import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Users from '../components/User/Users.vue'
import Role from '../view/Power/Role.vue'
import Power from '../view/Power/Power.vue'
import Cate from '../view/goods/Cate.vue'
import Params from '../view/goods/Params.vue'
import Classify from '../view/goods/Cassify.vue'
import Order from '../view/order/Order.vue'
import Data from '../view/data/Data.vue'
import Addgoods from '../view/goods/Addgoods.vue'

Vue.use(VueRouter)

const router = new VueRouter({
  routes:[
    {path:'/',redirect: '/login'},
    { path: '/login', component: Login },

    {path: '/home', component: Home,children:[
      {path:'/users',name:'users', component: Users},
      {path:'/roles',name:'roles',component:Role},
      {path:'/rights',name:'power',component:Power},
      {path:'/goods',name:'goods',component:Cate},
      {path:'/params',name:'params',component:Params},
      {path:'/categories',name:'classify',component:Classify},
      {path:'/orders',name:'order',component:Order},
      {path:'/reports',name:'data',component:Data},
      {path:'/goods/add',name:'add',component:Addgoods},
    ]},
    
  ]
})
router.beforeEach((to, from, next) => {
  if(to.path === '/login') return next()
  const Token = window.sessionStorage.getItem('token')
  if(!Token) return next('/login')
  next()
})

export default router
